﻿// ReSharper disable CppClangTidyModernizeUseNodiscard
#pragma once
#include <memory>
#include <glm/fwd.hpp>
#include <glm/geometric.hpp>
#include <glm/vec3.hpp>


class FCamera
{
public:

	FCamera(const glm::vec3& Position, const glm::vec3& WorldUp);

	glm::mat4 GetViewMat() const;

	float GetFOV()const { return FOV; }

	void SetFOV(const float InFOV) { FOV = glm::clamp(InFOV, 1.f, 45.f); }

	void SetPosition(const glm::vec3& Pos) { Position = Pos; }

	const glm::vec3& GetPosition() const { return Position; }

	const glm::vec3& GetRightVector()const;

	const glm::vec3& GetFrontVector() const;

	void AddYawOffset(const float YawOffset);

	void AddPitchOffset(const float PitchOffset);

private:

	void UpdateCameraVectors();

private:

	// 相机的基本属性
	glm::vec3 Position = {};
	glm::vec3 Front = {};
	glm::vec3 Up = {};
	glm::vec3 Right = {};
	glm::vec3 WorldUp = {};

	// 欧拉角

	// 绕 Y 轴  初始需要看向屏幕里面，所以偏角为 -90
	//			|
	//		----|----  + x
	//			|
	//			|  +z
	//          
	float Yaw = -90.f;


	//			|
	//		----|----  + z
	//			|
	//			|  +y
	// 
	float Pitch = 0.f;

	// FOV 即 视野的展开角度，正常是 45 度
	float FOV = 45.0f;

	bool VectorIsDirty = true;
};


inline std::shared_ptr<FCamera> CreateDefaultCamera()
{
	auto P = std::make_shared<FCamera>(glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0.0f, 1.0f, 0.0f));
	return P;
}
